package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mysql.jdbc.StringUtils;
import com.project.entity.Business;
import com.project.mapper.TBusinessMapper;
import com.project.service.IBusinessService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhangyang
 * @since 2021-10-06
 */
@Service
public class TBusinessServiceImpl extends ServiceImpl<TBusinessMapper, Business> implements IBusinessService {

    @Autowired
    private TBusinessMapper businessMapper;

    @Override
    public List<Business> findByItem( String shopowner, String name, String status, LocalDate start, LocalDate end) {
        QueryWrapper<Business> wrapper = new QueryWrapper<>();
        if (!StringUtils.isNullOrEmpty(shopowner)){
            wrapper.like("b_shopowner",shopowner);
        }
        if (!StringUtils.isNullOrEmpty(name)){
            wrapper.like("b_name",name);
        }
        if (!StringUtils.isNullOrEmpty(status)){
            wrapper.like("b_status",status);
        }
        if (start != null){
            wrapper.ge("b_startTime",start);
        }if (end != null){
            wrapper.le("b_startTime",end);
        }
        return businessMapper.selectList(wrapper);
    }

    @Override
    public Business findById(String id) {
        QueryWrapper<Business> wrapper = new QueryWrapper<>();
        wrapper.eq("b_code",id);
        return businessMapper.selectOne(wrapper);
    }
}
